package com.gitee.wsl.doc.prosemirror.state.command.selection

import com.gitee.wsl.doc.prosemirror.state.Command
import com.gitee.wsl.doc.prosemirror.state.CommandDispatch
import com.gitee.wsl.doc.prosemirror.state.EditorState

object DeleteSelection: Command {
    override fun exec(
        state: EditorState,
        dispatch: CommandDispatch?,
    ): Boolean {
        if (state.selection.isEmpty) return false
        dispatch?.invoke(state.tr.deleteSelection().scrollIntoView())
        return true
    }
}

val Command.Companion.deleteSelection get() = DeleteSelection